﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DiemChapNhanThe.Entities;
using DiemChapNhanThe.Data;

public partial class Controls_ControlDoanhNghiepMoiContent : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind_Data();
        }
    }
    protected void Bind_Data()
    {
        int ToTalRows = 0;
        int ToTalRows1 = 0;
        int ToTalRows2 = 0;

        
        string strHTML = "";
        TList<LoaiMatHang> Tlist_LoaiMatHang = DataRepository.LoaiMatHangProvider.GetPaged("TrangThai = 1", "Id DESC", 0, 0, out ToTalRows);
        if (Tlist_LoaiMatHang.Count > 0)
            for (int i = 0; i < Tlist_LoaiMatHang.Count; i++)
            {
                TList<MatHang> Tlist_MatHang = DataRepository.MatHangProvider.GetPaged("IdLoaiMatHang = " + Tlist_LoaiMatHang[i].Id, "NgayCapNhat DESC", 0, 3, out ToTalRows2);
                if (Tlist_MatHang.Count > 0)
                {
                    strHTML += "<div class=\"sub-tintuc-dnm\">";
                    strHTML += "<div class=\"img-sub-tintuc-dnm\">";
                    strHTML += "<img src='Upload/MatHang/" + Tlist_MatHang[0].AnhDaiDien + "' width='134px' height='107px' alt='1144953 3 2x'/>";
                    strHTML += "</div>";
                    strHTML += "<div class=\"content-sub-tintuc-dnm\">";
                    strHTML += "<p style=\"color: Red; font-size: 14px;\">" + Tlist_LoaiMatHang[i].TenMatHang + "</p>";
                    for (int k = 0; k < Tlist_MatHang.Count; k++)
                    {
                        string[] arrayStr = Tlist_MatHang[k].TomTat.Split(new string[] { "<br />" },
                                                           StringSplitOptions.RemoveEmptyEntries);
                        strHTML += "<a href='" + Tlist_MatHang[k].Id + "_" + Tlist_MatHang[k].IdSubMatHang + "_" + GetTieuDe(Tlist_MatHang[k].TieuDe) + "_DoanhNghiep.aspx'><p style=\"font-weight: bold;\">" + Tlist_MatHang[k].TieuDe + "</p></a><span>";
                        strHTML += "<p style=\"font-weight: normal;\">" + formatString(arrayStr[0], 35) + "</p>";
                        strHTML += "";
                        //strHTML += "<p>";
                    }
                    strHTML += "</div></div>";
                }  
            }
        litDNMoi.Text = strHTML;
    }
    public string GetTieuDe(object Char)
    {
        string s = Char.ToString();
        return Common.ConvertToUnSign(s);
    }
    public string formatString(string str, int n)
    {
        string kq = "";

        if (str.Length > n)
            kq = str.Substring(0, n + 1) + "...";
        else
            kq = str;

        return kq;
    }
    public string GetLoaiCongTy(object Id)
    {
        int s = Convert.ToInt32(Id.ToString());
        LoaiCongTy ent_LoaiCongTy = DataRepository.LoaiCongTyProvider.GetById(s);
        return ent_LoaiCongTy.TenLoaiCongTy;
    }
}